public class Num7 {

    /**
     * nice 弟弟
     * @param x
     * @return
     */
    int reverse(int x) {
        byte[] temps = new byte[10];
        int divisor = 10;
        int size = 0;

        for (int i = 0; x / (divisor / 10) != 0; i++){
            temps[i] = (byte)(x % divisor / (divisor / 10));
            x = x - x % divisor;
            size ++;
            if (x != 0 && divisor * 10 / 10 != divisor){
                temps[i + 1] = (byte)(x / divisor);
                size ++;
                break;
            } else {
                divisor *= 10;
            }
        }
        int res = 0;

        for (int i = 0; i < size; i++) {
            if (res > 0 && (res > Integer.MAX_VALUE / 10 || (res == Integer.MAX_VALUE / 10 && temps[i] > 7))
                    || res < 0 && (res < Integer.MIN_VALUE / 10 || (res == Integer.MIN_VALUE / 10 && temps[i] < -8))) {
                return 0;
            }

            res = (res * 10) + temps[i];
        }

        return res;
    }

    public static void main(String[] args) {
        Num7 num7 = new Num7();
        int num = 463847412;
        System.out.println(num);
        System.out.println(num7.reverse(num));
    }
}
